package com.qmx.launcher.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.open.androidtvwidget.leanback.adapter.GeneralAdapter;
import com.open.androidtvwidget.leanback.mode.OpenPresenter;
import com.qmx.launcher.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;

/**
 * @author ChengXiangtong
 * @create 2018/11/1
 * @Describe
 */
public class SleepOrScreenRecyclerViewPresenter extends OpenPresenter {

    private final List<String> labels;
    private GeneralAdapter mAdapter;
    public HashMap<Integer, Boolean> hashMap = new HashMap<>();

    public SleepOrScreenRecyclerViewPresenter(String[] str) {
        this.labels = new ArrayList<String>(str.length);
        for (int i = 0; i < str.length; i++) {
            labels.add(str[i]);
            hashMap.put(i, false);
        }
    }

    @Override
    public void setAdapter(GeneralAdapter adapter) {
        this.mAdapter = adapter;
    }

    public void setData(String[] str) {
        labels.clear();
        for (int i = 0; i < str.length; i++) {
            labels.add(str[i]);
        }
        mAdapter.notifyDataSetChanged();
    }


    @Override
    public int getItemCount() {
        return labels.size();
    }

    @Override
    public int getItemViewType(int position) {
        return 0;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sleeporscreen, parent, false);
        return new GridViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {
        GridViewHolder gridViewHolder = (GridViewHolder) viewHolder;
        TextView textView = gridViewHolder.tv_sleep_screen;
        CheckBox checkbox_sleep_screen = gridViewHolder.checkbox_sleep_screen;
        viewHolder.view.setTag(position);
        textView.setText(labels.get(position));
        checkbox_sleep_screen.setChecked(hashMap.get(position));
        //        for (int i = 0; i < hashMap.size(); i++) {
        //            if (hashMap.get(i)) {
        //                Log.e("onBindViewHolder", i + "----------" + (hashMap.get(i) == true));
        //
        //            } else {
        //                checkbox_sleep_screen.setChecked(false);
        //            }
        //        }
        System.err.println("onBindViewHolder===" + position);
    }


    public class GridViewHolder extends ViewHolder {
        public CheckBox checkbox_sleep_screen;
        public TextView tv_sleep_screen;

        public GridViewHolder(View itemView) {
            super(itemView);
            checkbox_sleep_screen = (CheckBox) itemView.findViewById(R.id.checkbox_sleep_screen);
            tv_sleep_screen = (TextView) itemView.findViewById(R.id.tv_sleep_screen);
        }

    }
}
